import { WereWolfWolfPhase } from "@/werewolf/phases/wolf";
import { WereWolfPhaseView } from "@/werewolf/phaseView";
import {
    EnchantmentTypes,
    ItemComponentTypes,
    ItemStack,
    world,
} from "@minecraft/server";
import { Dimensions } from "@sapi-game/constants";
import { ScriptRunner } from "@sapi-game/Runner/scriptRunner";

export class WolfCapmView extends WereWolfPhaseView<WereWolfWolfPhase> {
    override async runPhaseView(r: ScriptRunner): Promise<void> {
        this.players.title("§b§l预言家请闭眼");
        this.players.playSound("mob.elderguardian.curse", { volume: 0.6 });
        world.structureManager.place("lrs_center0", Dimensions.Overworld, {
            x: -207,
            y: -49,
            z: -187,
        });
        await r.wait(60);
        this.players.title("§c§l狼人请睁眼", "§c§l狼人将在夜间行动");
        this.giveItem();
        this.state.startPhase();
    }

    giveItem() {
        const skull = new ItemStack("wither_skeleton_skull");
        const chest = new ItemStack("netherite_chestplate");
        const leggings = new ItemStack("netherite_leggings");
        const boots = new ItemStack("netherite_boots");
        const sword = new ItemStack("diamond_sword");
        const wolfFur = new ItemStack("dried_kelp", 64);
        //名称
        wolfFur.nameTag = "§6§l狼毛";
        sword.nameTag = "§c§l狼人的刀";
        skull.nameTag = "§c狼头";
        //附魔
        const sharpness = EnchantmentTypes.get("sharpness");
        if (sharpness) {
            sword.getComponent(ItemComponentTypes.Enchantable)?.addEnchantment({
                type: sharpness,
                level: 5,
            });
        }
        this.state.getWolves().forEach((p) => {
            p.giveItem(sword);
            p.giveItem(wolfFur);
            p.giveItem(skull);
            p.giveItem(chest);
            p.giveItem(leggings);
            p.giveItem(boots);
        });
    }
}
